import { axiosInstance } from "@halo-dev/api-client";
import type {
  ProductType,
  Product,
  ProductTypeListResponse,
  ProductListResponse,
  ProductTypeListRequest,
  ProductListRequest,
  CreateProductTypeRequest,
  UpdateProductTypeRequest,
  DeleteProductTypeRequest,
  CreateProductRequest,
  UpdateProductRequest,
  DeleteProductRequest,
} from "@console/types";

export const productTypeApiClient = {
  listProductTypes: (params: ProductTypeListRequest) => {
    return axiosInstance.get<ProductTypeListResponse>("/apis/content.halo.run/v1alpha1/product-types", {
      params,
    });
  },

  createProductType: (data: CreateProductTypeRequest) => {
    return axiosInstance.post<ProductType>("/apis/content.halo.run/v1alpha1/product-types", data.productType);
  },

  updateProductType: (data: UpdateProductTypeRequest) => {
    return axiosInstance.put<ProductType>(`/apis/content.halo.run/v1alpha1/product-types/${data.name}`, data.productType);
  },

  deleteProductType: (data: DeleteProductTypeRequest) => {
    return axiosInstance.delete(`/apis/content.halo.run/v1alpha1/product-types/${data.name}`);
  },

  getProductType: (name: string) => {
    return axiosInstance.get<ProductType>(`/apis/content.halo.run/v1alpha1/product-types/${name}`);
  },
};

export const productApiClient = {
  listProducts: (params: ProductListRequest) => {
    return axiosInstance.get<ProductListResponse>("/apis/content.halo.run/v1alpha1/products", {
      params,
    });
  },

  createProduct: (data: CreateProductRequest) => {
    return axiosInstance.post<Product>("/apis/content.halo.run/v1alpha1/products", data.product);
  },

  updateProduct: (data: UpdateProductRequest) => {
    return axiosInstance.put<Product>(`/apis/content.halo.run/v1alpha1/products/${data.name}`, data.product);
  },

  deleteProduct: (data: DeleteProductRequest) => {
    return axiosInstance.delete(`/apis/content.halo.run/v1alpha1/products/${data.name}`);
  },

  getProduct: (name: string) => {
    return axiosInstance.get<Product>(`/apis/content.halo.run/v1alpha1/products/${name}`);
  },
};